package com.um.jdy.platform.recharge.controller;

import com.um.jdy.platform.recharge.entity.dto.RechargeOrderExportDTO;
import com.um.jdy.platform.recharge.entity.dto.RechargeOrderPageDTO;
import com.um.jdy.platform.recharge.entity.dto.RefundDTO;
import com.um.jdy.platform.recharge.entity.vo.RechargeOrderItemVO;
import com.um.jdy.platform.recharge.manager.RechargeOrderManager;
import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.annotation.TokenRequired;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.controller.BaseController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.params.ExportParams;
import com.um.springboot.starter.orm.params.PageParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 充值订单
 *
 * @author cs
 * 日期 2023/5/25
 * 版权所有 广州优匠科技有限公司
 */
@Api(tags = "充值订单")
@Validated
@RestController
@RequestMapping("/api/v1/cms/recharge/order")
@ApiPermission("recharge")
@TokenRequired
public class RechargeOrderController extends BaseController<RechargeOrderManager> {

    /**
     * 分页查询订单
     *
     * @param params
     * @return
     */
    @ApiPermission("page")
    @ApiOperation("分页查询订单")
    @PostMapping("page")
    public Response<Page<RechargeOrderItemVO>> page(@RequestBody RechargeOrderPageDTO params) {
        PageParams pageParams = params.toPageParams(
                new String[]{"orderNo","outTradeNo","nickname","mobile"},
                new String[]{"o.order_no","o.out_trade_no","u.nickname","u.mobile"},
                "o.create_time","beginTime","endTime");
        return manager.page(pageParams);
    }

    /**
     * 充值退款
     * @param dto
     * @return
     */
    @ApiPermission("refund")
    @ApiOperation("充值退款")
    @PostMapping("refund")
    public Response refund(@RequestBody RefundDTO dto){
        return manager.refund(dto.getOrderNo(),dto.getAmount());
    }

    /**
     * 导出充值订单
     * @param params
     * @return
     */
    @ApiPermission("export")
    @ApiOperation("导出充值订单")
    @PostMapping("export_page")
    public Response exportPage(@RequestBody RechargeOrderExportDTO params) {
        ExportParams exportParams = params.toExportParams(
                new String[]{"orderNo","outTradeNo","nickname","mobile"},
                new String[]{"o.order_no","o.out_trade_no","u.nickname","u.mobile"},
                "o.create_time","beginTime","endTime");
        return manager.exportPage(exportParams);
    }
}
